/**************************************************************************************************
/// Copyright (c) 2006-2018, RT-Thread Development Team
/// All rights reserved.
///
/// \author: Alex
///
/// \file: sysctrl.h
/// \brief: Header for system control module.
///
///
///
/// \version: 1.0
/// \date: Mar. 04, 2021
**************************************************************************************************/
#include "chargectrl.h" 
#include "cJSON.h"  
#include "gprsProcess.h"

#ifndef _LIANQIAOCHARGE_H_
#define _LIANQIAOCHARGE_H_
        

 
//#define  _USING_LQCD_SERVER   

/**************************************************************************************************
*                              Macro definition                                                   *
**************************************************************************************************/
#define LQCD_TIMING_DEALY_SECONDS (3600)
#define LQCD_HEART_TICK_SECONDS 60
#define LQCD_ACK_TIMEOUT_MSECS  (5000)
#define TRUE                    (1)
#define FALSE                   !(TRUE)


#define MAX_CONNECTION_TIME_OUT             180000
#define LQCD_PILE_DEV_ID                  "100221000046"
#define LQCD_PRICE_MAX                      (12)
#define LQCD_PRICE_DEFAULT                  (1.0)
#define LQCD_ACK_DELAY_MS                    (15000)

/**************************************************************************************************
*                              Enumeration type definition                                        *
**************************************************************************************************/

/**************************************************************************************************
*                              Struct type definition                                             *
**************************************************************************************************/
#pragma pack(1)
typedef struct
{
    char cValid;
    float fFee;
    unsigned short usStartTime;//minutes00:01   1  ,  01:01  61
    unsigned short usEndTime;  //minutes00:01   1  ,  01:01  61
}ST_PRICE;

typedef struct
{
    float sumEle;
    float sumMoney;
    float ele[LQCD_PRICE_MAX];
    float money[LQCD_PRICE_MAX];
}stru_LQCDConsume;
#pragma pack()

/**************************************************************************************************
*                              variables declaration                                             *
**************************************************************************************************/
extern ST_PRICE g_astPrice[LQCD_PRICE_MAX];
extern stru_LQCDConsume  g_strLQCDconsume;
extern unsigned short g_LQCD_TimingDelay_secs;
/**************************************************************************************************
*                              Functions declaration                                              *
**************************************************************************************************/
void Lqcd_init(void);
//extern void Lqcd_RcvMsgProc(const char *pcRcvMsg);
extern void Lqcd_RcvMsgProc(const char *pcRcvMsg,unsigned short length);
extern unsigned short Lqcd_loadHeartFrame(char *buff);
extern unsigned short Lqcd_loadLogonFrame(char *buff);
extern void Lqcd_RebootProc(void);
extern void Lqcd_StartChargeProc(char *txnNo);
extern void Lqcd_StopChargeProc(char *txnNo);
extern void Lqcd_GetTimeFromTimeString(char *pcTime, unsigned char *pucStartTime, unsigned char *pucEndTime);
extern void Lqcd_SendRemoteCtrlAck(char *pCmdId, unsigned char ucResult, char *txnNo);
extern unsigned char checkIfJsonFrame(char *buff);
void Lqcd_savePriceFlie(void);
void Lqcd_readPrceFile(void);
void Lqcd_init(void);
void lqcd_consumeClear(void);
void lqcd_CalcConsumeMoneyAndEle(void);
float lqcd_getChargeMoney(void);
float LQCD_GetPrice(unsigned char priceIndex);
unsigned char LQCD_GetPriceIndex(void);
void lqcd_sendAlarm(unsigned char Alarmflag,unsigned short AlarmCode);
extern int lqcd_SendChargeRTInfo(unsigned char ucChargeState, ST_RT_TRADE *pstTrade);
void lqcd_WriteOfflineTrade2TradeFile(ST_TRADE_INFO *pstTradeInfo);
void lqcd_SendRTTrade(unsigned char ucChargeStatus, unsigned int uiStopReason);
extern void Lqcd_RemoteControlMsgDealwith(cJSON *json);
extern void Lqcd_QueryConfigMsgDealwith(cJSON *json);
extern void Lqcd_TradeAckMsgDealwith(cJSON *json);
extern void Lqcd_LogonAckMsgDealwith(cJSON *json);
extern void Lqcd_RemoteChargeConfirmDealwith(cJSON *json);
unsigned char lqcd_getOfflineTrade(ST_TRADE_INFO *strLqcdChargeOfflineRecord);
void lqcd_saveTradeMsg(uint8_t reason);
ST_TRADE_INFO lqcd_loadTrade(void);
void lqcd_loadProgress(void);
int lqcd_SendOfflineChargeRecord(ST_TRADE_INFO *pstTrade);
void lqcd_ClearOfflineTrade(void);

void Lqcd_SwipCardRequsetCharge(unsigned char *buff);

unsigned char GetNfcRequestLqcdResult(void);
unsigned char GetNfcRequestLqcdFailedResaon(void);
void ClearNfcRequestLqcdResult(void);

void Lqcd_RemoteUpdateRespone(int res);
uint8_t LqcdDateCrcCheck(const char * dat,int length);
void LqcdGetCrcDate(char *root,int length);
void lqcd_RemoteRebootResopne(uint8_t res,char* txnNo);
void lqcd_reboot(uint8_t rebType);
void RebootThreadStart(void* parameter);
void lqcd_RemoteBalanceUpdate(uint8_t res,char* txnNo);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
        
#endif
//end file



